package com.apex.shared.mybatis.generator;

import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
import org.springframework.stereotype.Component;

/**
 * Apex CustomIdGenerator
 *
 * @author Bangda Xiao
 */
@Component
public class CustomIdGenerator implements IdentifierGenerator {
    @Override
    public Number nextId(Object entity) {
        return null;
    }

    @Override
    public String nextUUID(Object entity) {
        String entityName = entity.getClass().getAnnotation(TableName.class).value();
        String[] subKeys = entityName.split("_");
        String bizKey = subKeys[0];
        long timeStamp = System.currentTimeMillis();
        String uuid = bizKey + "_" + timeStamp;
        return uuid;
    }
}
